<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 账号登录</span>
        </template>
        <login-account ref="loginref" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
        </template>
        <login-phone ref="phoneref"></login-phone>
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeeoPasswoed">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="Login" @click="LoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import loginAccount from './login-account.vue'
import phoneAccount from './login-phone.vue'
import LoginPhone from './login-phone.vue'

export default defineComponent({
  components: { loginAccount, LoginPhone },
  setup() {
    //定义属性
    const isKeeoPasswoed = ref(true)
    //保存account组件的实例对象类型是loginAccount
    const loginref = ref<InstanceType<typeof loginAccount>>()
    const phoneref = ref<InstanceType<typeof phoneAccount>>()
    const currentTab = ref<string>('account')

    //定义方法
    const LoginClick = () => {
      if (currentTab.value === 'account') {
        loginref.value?.loginactive(isKeeoPasswoed.value)
      } else {
        phoneref.value?.phoneactive()
      }
    }
    return {
      isKeeoPasswoed,
      loginref,
      currentTab,
      phoneref,
      LoginClick
    }
  }
})
</script>

<style scoped lang="less">
.login-panel {
  margin-bottom: 150px;
  width: 320px;

  .title {
    text-align: center;
  }

  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .Login {
    margin-top: 10px;
    width: 100%;
    height: 40px;
  }
}
</style>
